import { Sequelize } from 'sequelize';
import { config } from '../config/database';
import { initUser } from './User';
import { initInterestTag } from './InterestTag';
import { initCircle } from './Circle';
import { initCirclePost } from './CirclePost';
import { initCircleComment } from './CircleComment';
import { initCirclePostLike } from './CirclePostLike';
import { initCircleCommentLike } from './CircleCommentLike';
import { initMessage } from './Message';
import { initSocialRelation } from './SocialRelation';
import { initUserInterestTag } from './UserInterestTag';

const sequelize = new Sequelize(config.database, config.username, config.password, {
    host: config.host,
    dialect: config.dialect,
    logging: false
});

// 初始化所有模型
initUser(sequelize);
initInterestTag(sequelize);
initCircle(sequelize);
initCirclePost(sequelize);
initCircleComment(sequelize);
initCirclePostLike(sequelize);
initCircleCommentLike(sequelize);
initMessage(sequelize);
initSocialRelation(sequelize);
initUserInterestTag(sequelize);

// 建立模型之间的关联
Object.values(sequelize.models).forEach((model: any) => {
    if (model.associate) {
        model.associate(sequelize.models);
    }
});

export { sequelize };
export { default as User } from './User';
export { default as InterestTag } from './InterestTag';
export { default as Circle } from './Circle';
export { default as CirclePost } from './CirclePost';
export { default as CircleComment } from './CircleComment';
export { default as CirclePostLike } from './CirclePostLike';
export { default as CircleCommentLike } from './CircleCommentLike';
export { default as Message } from './Message';
export { default as SocialRelation } from './SocialRelation';
export { default as UserInterestTag } from './UserInterestTag'; 